//
//  WowNotificationSwitchManager.m
//  PersonalOCTest
//
//  Created by zlf on 2025/8/20.
//

#import "WowNotificationSwitchManager.h"

@implementation WowNotificationSwitchManager{
//    NSMutableArray<id<WowNotificationSwitchStrategy>> *_strategies;
}

+ (instancetype)sharedManager {
    static WowNotificationSwitchManager *instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

- (instancetype)init {
    if (self = [super init]) {
//        _strategies = [NSMutableArray array];
        [self setupDefaultStrategies];
    }
    return self;
}

- (void)setupDefaultStrategies {
    // 注册默认策略（按优先级排序）
//    [self registerStrategy:[[WowMainSyncSwitchStrategy alloc] init]];
//    [self registerStrategy:[[WowAppSwitchStrategy alloc] init]];
//    [self registerStrategy:[[WowThirdPartyAppSwitchStrategy alloc] init]];
}

//- (void)registerStrategy:(id<WowNotificationSwitchStrategy>)strategy {
//    if (!strategy) return;
//    
//    // 避免重复注册
//    for (id<WowNotificationSwitchStrategy> existingStrategy in _strategies) {
//        if ([existingStrategy class] == [strategy class]) {
//            return;
//        }
//    }
//    
//    [_strategies addObject:strategy];
//    
//    // 按优先级排序
//    [_strategies sortUsingComparator:^NSComparisonResult(id<WowNotificationSwitchStrategy> obj1,
//                                                        id<WowNotificationSwitchStrategy> obj2) {
//        NSInteger priority1 = [obj1 respondsToSelector:@selector(priority)] ? [obj1 priority] : NSIntegerMax;
//        NSInteger priority2 = [obj2 respondsToSelector:@selector(priority)] ? [obj2 priority] : NSIntegerMax;
//        
//        if (priority1 < priority2) return NSOrderedAscending;
//        if (priority1 > priority2) return NSOrderedDescending;
//        return NSOrderedSame;
//    }];
//}

//- (BOOL)handleSwitchWithTag:(WowNotificationSwitchTag)tag context:(WowSwitchContext *)context {
//    // 查找能处理该tag的策略
//    for (id<WowNotificationSwitchStrategy> strategy in _strategies) {
//        if ([strategy canHandleTag:tag]) {
//            NSLog(@"Using strategy: %@", [strategy respondsToSelector:@selector(strategyDescription)] ?
//                  [strategy strategyDescription] : NSStringFromClass([strategy class]));
//            
//            [strategy handleSwitchWithContext:context];
//            return YES;
//        }
//    }
//    
//    NSLog(@"No strategy found for tag: %ld", (long)tag);
//    return NO;
//}

//- (NSArray<id<WowNotificationSwitchStrategy>> *)allStrategies {
//    return [_strategies copy];
//}
//
//- (void)clearAllStrategies {
//    [_strategies removeAllObjects];
//}

@end
